package com.yuqing.sentimentapp.workspace.statistics;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.androidkun.xtablayout.XTabLayout;
import com.linkface.baselibrary.http.BaseBean;
import com.yuqing.sentimentapp.R;
import com.yuqing.sentimentapp.base.BaseActivity;
import com.yuqing.sentimentapp.base.BaseObserver;
import com.yuqing.sentimentapp.module.ModuleManager;
import com.yuqing.sentimentapp.workspace.statistics.entity.StatisticsInfoResult;
import com.yuqing.sentimentapp.workspace.statistics.entity.StatisticsReportResult;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * 每日报送信息统计
 * Created by shenhe on 2020/4/3.
 */
public class StatisticsFillInActivity extends BaseActivity {

    @BindView(R.id.iv_back)
    ImageView mIvBack;
    @BindView(R.id.tv_save)
    TextView mTvSave;
    @BindView(R.id.tabs)
    XTabLayout mTabs;
    @BindView(R.id.et_fireAlarmCount)
    EditText mEtFireAlarmCount;
    @BindView(R.id.et_fireFireCount)
    EditText mEtFireFireCount;
    @BindView(R.id.et_fireOutCount)
    EditText mEtFireOutCount;
    @BindView(R.id.et_fireCarCount)
    EditText mEtFireCarCount;
    @BindView(R.id.et_fireFiremanCount)
    EditText mEtFireFiremanCount;
    @BindView(R.id.et_fireDeathCount)
    EditText mEtFireDeathCount;
    @BindView(R.id.et_fireInjuredCount)
    EditText mEtFireInjuredCount;
    @BindView(R.id.et_fireRescueCount)
    EditText mEtFireRescueCount;
    @BindView(R.id.et_fireEvacuationCount)
    EditText mEtFireEvacuationCount;
    @BindView(R.id.et_fireUseCount)
    EditText mEtFireUseCount;
    @BindView(R.id.ll_fire)
    LinearLayout mLlFire;
    @BindView(R.id.et_rescueAlarmCount)
    EditText mEtRescueAlarmCount;
    @BindView(R.id.et_rescueOutCount)
    EditText mEtRescueOutCount;
    @BindView(R.id.et_rescueCarCount)
    EditText mEtRescueCarCount;
    @BindView(R.id.et_rescueFiremanCount)
    EditText mEtRescueFiremanCount;
    @BindView(R.id.et_rescueDeathCount)
    EditText mEtRescueDeathCount;
    @BindView(R.id.et_rescueInjuredCount)
    EditText mEtRescueInjuredCount;
    @BindView(R.id.et_rescueRescueCount)
    EditText mEtRescueRescueCount;
    @BindView(R.id.et_rescueEvacuationCount)
    EditText mEtRescueEvacuationCount;
    @BindView(R.id.et_rescueUseCount)
    EditText mEtRescueUseCount;
    @BindView(R.id.ll_rescue)
    LinearLayout mLlRescue;
    @BindView(R.id.et_explosionAlarmCount)
    EditText mEtExplosionAlarmCount;
    @BindView(R.id.et_explosionCarCount)
    EditText mEtExplosionCarCount;
    @BindView(R.id.et_explosionFiremanCount)
    EditText mEtExplosionFiremanCount;
    @BindView(R.id.et_explosionDeathCount)
    EditText mEtExplosionDeathCount;
    @BindView(R.id.et_explosionInjuredCount)
    EditText mEtExplosionInjuredCount;
    @BindView(R.id.et_explosionRescueCount)
    EditText mEtExplosionRescueCount;
    @BindView(R.id.et_explosionEvacuationCount)
    EditText mEtExplosionEvacuationCount;
    @BindView(R.id.et_explosionUseCount)
    EditText mEtExplosionUseCount;
    @BindView(R.id.ll_explosion)
    LinearLayout mLlExplosion;
    @BindView(R.id.et_trafficAlarmCount)
    EditText mEtTrafficAlarmCount;
    @BindView(R.id.et_trafficCarCount)
    EditText mEtTrafficCarCount;
    @BindView(R.id.et_trafficFiremanCount)
    EditText mEtTrafficFiremanCount;
    @BindView(R.id.et_trafficDeathCount)
    EditText mEtTrafficDeathCount;
    @BindView(R.id.et_trafficInjuredCount)
    EditText mEtTrafficInjuredCount;
    @BindView(R.id.et_trafficRescueCount)
    EditText mEtTrafficRescueCount;
    @BindView(R.id.et_trafficUseCount)
    EditText mEtTrafficUseCount;
    @BindView(R.id.ll_traffic)
    LinearLayout mLlTraffic;
    @BindView(R.id.et_collapseAlarmCount)
    EditText mEtCollapseAlarmCount;
    @BindView(R.id.et_collapseCarCount)
    EditText mEtCollapseCarCount;
    @BindView(R.id.et_collapseFiremanCount)
    EditText mEtCollapseFiremanCount;
    @BindView(R.id.et_collapseDeathCount)
    EditText mEtCollapseDeathCount;
    @BindView(R.id.et_collapseInjuredCount)
    EditText mEtCollapseInjuredCount;
    @BindView(R.id.et_collapseRescueCount)
    EditText mEtCollapseRescueCount;
    @BindView(R.id.et_collapseEvacuationCount)
    EditText mEtCollapseEvacuationCount;
    @BindView(R.id.et_collapseUseCount)
    EditText mEtCollapseUseCount;
    @BindView(R.id.ll_collapse)
    LinearLayout mLlCollapse;
    @BindView(R.id.et_reportInstructionCount)
    EditText mEtReportInstructionCount;
    @BindView(R.id.et_reportImportantCount)
    EditText mEtReportImportantCount;
    @BindView(R.id.et_reportNewsCount)
    EditText mEtReportNewsCount;
    @BindView(R.id.ll_report)
    LinearLayout mLlReport;
    @BindView(R.id.et_useInstructionCount)
    EditText mEtUseInstructionCount;
    @BindView(R.id.et_useImportantCount)
    EditText mEtUseImportantCount;
    @BindView(R.id.et_useNewsCount)
    EditText mEtUseNewsCount;
    @BindView(R.id.ll_use)
    LinearLayout mLlUse;
    @BindView(R.id.et_phone)
    EditText mEtPhone;
    @BindView(R.id.et_duty_leader)
    EditText mEtDutyLeader;
    @BindView(R.id.et_problem)
    EditText mEtProblem;
    @BindView(R.id.et_remark)
    EditText mEtRemark;


    private boolean editEnable = true;
    private StatisticsInfoResult.DataBean actionInfo;
    private StatisticsReportResult.DataBean.SubSumBean subSum;
    /**
     * 从已上报列表跳转过来的
     */
    private StatisticsReportResult.DataBean.ReportsBean reportsInfo;


    public static void goActivity(Activity activity, StatisticsInfoResult.DataBean actionInfo, StatisticsReportResult.DataBean.SubSumBean subSum) {
        Intent intent = new Intent(activity, StatisticsFillInActivity.class);
        intent.putExtra("actionInfo", actionInfo);
        intent.putExtra("subSum", subSum);
        activity.startActivity(intent);
    }

    public static void goActivity(Activity activity, StatisticsReportResult.DataBean.ReportsBean reportsInfo) {
        Intent intent = new Intent(activity, StatisticsFillInActivity.class);
        intent.putExtra("reportsInfo", reportsInfo);
        activity.startActivity(intent);
    }


    @Override
    public int getLayoutId() {
        return R.layout.activity_statistics_fill_in;
    }

    @Override
    public void initPresenter() {
        Intent intent = getIntent();
        if (intent == null) return;
        actionInfo = ((StatisticsInfoResult.DataBean) intent.getSerializableExtra("actionInfo"));
        subSum = ((StatisticsReportResult.DataBean.SubSumBean) intent.getSerializableExtra("subSum"));

        reportsInfo = ((StatisticsReportResult.DataBean.ReportsBean) intent.getSerializableExtra("reportsInfo"));

    }

    @Override
    public void initView() {
        if (actionInfo != null) {
            mEtFireAlarmCount.setText(actionInfo.getFireAlarmCount());
            mEtFireCarCount.setText(actionInfo.getFireCarCount());
            mEtFireDeathCount.setText(actionInfo.getFireDeathCount());
            mEtFireEvacuationCount.setText(actionInfo.getFireEvacuationCount());
            mEtFireFireCount.setText(actionInfo.getFireFireCount());
            mEtFireFiremanCount.setText(actionInfo.getFireFiremanCount());
            mEtFireInjuredCount.setText(actionInfo.getFireInjuredCount());
            mEtFireOutCount.setText(actionInfo.getFireOutCount());
            mEtFireRescueCount.setText(actionInfo.getFireRescueCount());
            mEtFireUseCount.setText(actionInfo.getFireUseCount());

            mEtRescueAlarmCount.setText(actionInfo.getRescueAlarmCount());
            mEtRescueCarCount.setText(actionInfo.getRescueCarCount());
            mEtRescueDeathCount.setText(actionInfo.getRescueDeathCount());
            mEtRescueEvacuationCount.setText(actionInfo.getRescueEvacuationCount());
            mEtRescueFiremanCount.setText(actionInfo.getRescueFiremanCount());
            mEtRescueInjuredCount.setText(actionInfo.getRescueInjuredCount());
            mEtRescueOutCount.setText(actionInfo.getRescueOutCount());
            mEtRescueRescueCount.setText(actionInfo.getRescueRescueCount());
            mEtRescueUseCount.setText(actionInfo.getRescueUseCount());

            mEtExplosionAlarmCount.setText(actionInfo.getExplosionAlarmCount());
            mEtExplosionCarCount.setText(actionInfo.getExplosionCarCount());
            mEtExplosionDeathCount.setText(actionInfo.getExplosionDeathCount());
            mEtExplosionEvacuationCount.setText(actionInfo.getExplosionEvacuationCount());
            mEtExplosionFiremanCount.setText(actionInfo.getExplosionFiremanCount());
            mEtExplosionInjuredCount.setText(actionInfo.getExplosionInjuredCount());
            mEtExplosionRescueCount.setText(actionInfo.getExplosionRescueCount());
            mEtExplosionUseCount.setText(actionInfo.getExplosionUseCount());

            mEtTrafficAlarmCount.setText(actionInfo.getTrafficAlarmCount());
            mEtTrafficCarCount.setText(actionInfo.getTrafficCarCount());
            mEtTrafficDeathCount.setText(actionInfo.getTrafficDeathCount());
            mEtTrafficFiremanCount.setText(actionInfo.getTrafficFiremanCount());
            mEtTrafficInjuredCount.setText(actionInfo.getTrafficInjuredCount());
            mEtTrafficRescueCount.setText(actionInfo.getTrafficRescueCount());
            mEtTrafficUseCount.setText(actionInfo.getTrafficUseCount());

            mEtCollapseAlarmCount.setText(actionInfo.getCollapseAlarmCount());
            mEtCollapseCarCount.setText(actionInfo.getCollapseCarCount());
            mEtCollapseDeathCount.setText(actionInfo.getCollapseDeathCount());
            mEtCollapseEvacuationCount.setText(actionInfo.getCollapseEvacuationCount());
            mEtCollapseFiremanCount.setText(actionInfo.getCollapseFiremanCount());
            mEtCollapseInjuredCount.setText(actionInfo.getCollapseInjuredCount());
            mEtCollapseRescueCount.setText(actionInfo.getCollapseRescueCount());
            mEtCollapseUseCount.setText(actionInfo.getCollapseUseCount());

            mEtReportInstructionCount.setText(actionInfo.getReportInstructionCount());
            mEtReportImportantCount.setText(actionInfo.getReportImportantCount());
            mEtReportNewsCount.setText(actionInfo.getReportNewsCount());

            mEtUseInstructionCount.setText(actionInfo.getUseInstructionCount());
            mEtUseImportantCount.setText(actionInfo.getUseImportantCount());
            mEtUseNewsCount.setText(actionInfo.getUseNewsCount());

            mEtPhone.setText(actionInfo.getPhone());
            mEtDutyLeader.setText(actionInfo.getDutyLeader());
            mEtProblem.setText(actionInfo.getProblem());
            mEtRemark.setText(actionInfo.getRemark());
        } else {
            if (subSum != null) {
                mEtFireAlarmCount.setText(subSum.getFireAlarmCount());
                mEtFireCarCount.setText(subSum.getFireCarCount());
                mEtFireDeathCount.setText(subSum.getFireDeathCount());
                mEtFireEvacuationCount.setText(subSum.getFireEvacuationCount());
                mEtFireFireCount.setText(subSum.getFireFireCount());
                mEtFireFiremanCount.setText(subSum.getFireFiremanCount());
                mEtFireInjuredCount.setText(subSum.getFireInjuredCount());
                mEtFireOutCount.setText(subSum.getFireOutCount());
                mEtFireRescueCount.setText(subSum.getFireRescueCount());
                mEtFireUseCount.setText(subSum.getFireUseCount());

                mEtRescueAlarmCount.setText(subSum.getRescueAlarmCount());
                mEtRescueCarCount.setText(subSum.getRescueCarCount());
                mEtRescueDeathCount.setText(subSum.getRescueDeathCount());
                mEtRescueEvacuationCount.setText(subSum.getRescueEvacuationCount());
                mEtRescueFiremanCount.setText(subSum.getRescueFiremanCount());
                mEtRescueInjuredCount.setText(subSum.getRescueInjuredCount());
                mEtRescueOutCount.setText(subSum.getRescueOutCount());
                mEtRescueRescueCount.setText(subSum.getRescueRescueCount());
                mEtRescueUseCount.setText(subSum.getRescueUseCount());

                mEtExplosionAlarmCount.setText(subSum.getExplosionAlarmCount());
                mEtExplosionCarCount.setText(subSum.getExplosionCarCount());
                mEtExplosionDeathCount.setText(subSum.getExplosionDeathCount());
                mEtExplosionEvacuationCount.setText(subSum.getExplosionEvacuationCount());
                mEtExplosionFiremanCount.setText(subSum.getExplosionFiremanCount());
                mEtExplosionInjuredCount.setText(subSum.getExplosionInjuredCount());
                mEtExplosionRescueCount.setText(subSum.getExplosionRescueCount());
                mEtExplosionUseCount.setText(subSum.getExplosionUseCount());

                mEtTrafficAlarmCount.setText(subSum.getTrafficAlarmCount());
                mEtTrafficCarCount.setText(subSum.getTrafficCarCount());
                mEtTrafficDeathCount.setText(subSum.getTrafficDeathCount());
                mEtTrafficFiremanCount.setText(subSum.getTrafficFiremanCount());
                mEtTrafficInjuredCount.setText(subSum.getTrafficInjuredCount());
                mEtTrafficRescueCount.setText(subSum.getTrafficRescueCount());
                mEtTrafficUseCount.setText(subSum.getTrafficUseCount());

                mEtCollapseAlarmCount.setText(subSum.getCollapseAlarmCount());
                mEtCollapseCarCount.setText(subSum.getCollapseCarCount());
                mEtCollapseDeathCount.setText(subSum.getCollapseDeathCount());
                mEtCollapseEvacuationCount.setText(subSum.getCollapseEvacuationCount());
                mEtCollapseFiremanCount.setText(subSum.getCollapseFiremanCount());
                mEtCollapseInjuredCount.setText(subSum.getCollapseInjuredCount());
                mEtCollapseRescueCount.setText(subSum.getCollapseRescueCount());
                mEtCollapseUseCount.setText(subSum.getCollapseUseCount());

                mEtReportInstructionCount.setText(subSum.getReportInstructionCount());
                mEtReportImportantCount.setText(subSum.getReportImportantCount());
                mEtReportNewsCount.setText(subSum.getReportNewsCount());

                mEtUseInstructionCount.setText(subSum.getUseInstructionCount());
                mEtUseImportantCount.setText(subSum.getUseImportantCount());
                mEtUseNewsCount.setText(subSum.getUseNewsCount());
            }
        }

        /**
         * 从已上报列表跳转过来的，不可编辑，隐藏保存按钮
         */
        if (reportsInfo != null) {
            mEtFireAlarmCount.setText(reportsInfo.getFireAlarmCount());
            mEtFireCarCount.setText(reportsInfo.getFireCarCount());
            mEtFireDeathCount.setText(reportsInfo.getFireDeathCount());
            mEtFireEvacuationCount.setText(reportsInfo.getFireEvacuationCount());
            mEtFireFireCount.setText(reportsInfo.getFireFireCount());
            mEtFireFiremanCount.setText(reportsInfo.getFireFiremanCount());
            mEtFireInjuredCount.setText(reportsInfo.getFireInjuredCount());
            mEtFireOutCount.setText(reportsInfo.getFireOutCount());
            mEtFireRescueCount.setText(reportsInfo.getFireRescueCount());
            mEtFireUseCount.setText(reportsInfo.getFireUseCount());

            mEtRescueAlarmCount.setText(reportsInfo.getRescueAlarmCount());
            mEtRescueCarCount.setText(reportsInfo.getRescueCarCount());
            mEtRescueDeathCount.setText(reportsInfo.getRescueDeathCount());
            mEtRescueEvacuationCount.setText(reportsInfo.getRescueEvacuationCount());
            mEtRescueFiremanCount.setText(reportsInfo.getRescueFiremanCount());
            mEtRescueInjuredCount.setText(reportsInfo.getRescueInjuredCount());
            mEtRescueOutCount.setText(reportsInfo.getRescueOutCount());
            mEtRescueRescueCount.setText(reportsInfo.getRescueRescueCount());
            mEtRescueUseCount.setText(reportsInfo.getRescueUseCount());

            mEtExplosionAlarmCount.setText(reportsInfo.getExplosionAlarmCount());
            mEtExplosionCarCount.setText(reportsInfo.getExplosionCarCount());
            mEtExplosionDeathCount.setText(reportsInfo.getExplosionDeathCount());
            mEtExplosionEvacuationCount.setText(reportsInfo.getExplosionEvacuationCount());
            mEtExplosionFiremanCount.setText(reportsInfo.getExplosionFiremanCount());
            mEtExplosionInjuredCount.setText(reportsInfo.getExplosionInjuredCount());
            mEtExplosionRescueCount.setText(reportsInfo.getExplosionRescueCount());
            mEtExplosionUseCount.setText(reportsInfo.getExplosionUseCount());

            mEtTrafficAlarmCount.setText(reportsInfo.getTrafficAlarmCount());
            mEtTrafficCarCount.setText(reportsInfo.getTrafficCarCount());
            mEtTrafficDeathCount.setText(reportsInfo.getTrafficDeathCount());
            mEtTrafficFiremanCount.setText(reportsInfo.getTrafficFiremanCount());
            mEtTrafficInjuredCount.setText(reportsInfo.getTrafficInjuredCount());
            mEtTrafficRescueCount.setText(reportsInfo.getTrafficRescueCount());
            mEtTrafficUseCount.setText(reportsInfo.getTrafficUseCount());

            mEtCollapseAlarmCount.setText(reportsInfo.getCollapseAlarmCount());
            mEtCollapseCarCount.setText(reportsInfo.getCollapseCarCount());
            mEtCollapseDeathCount.setText(reportsInfo.getCollapseDeathCount());
            mEtCollapseEvacuationCount.setText(reportsInfo.getCollapseEvacuationCount());
            mEtCollapseFiremanCount.setText(reportsInfo.getCollapseFiremanCount());
            mEtCollapseInjuredCount.setText(reportsInfo.getCollapseInjuredCount());
            mEtCollapseRescueCount.setText(reportsInfo.getCollapseRescueCount());
            mEtCollapseUseCount.setText(reportsInfo.getCollapseUseCount());

            mEtReportInstructionCount.setText(reportsInfo.getReportInstructionCount());
            mEtReportImportantCount.setText(reportsInfo.getReportImportantCount());
            mEtReportNewsCount.setText(reportsInfo.getReportNewsCount());

            mEtUseInstructionCount.setText(reportsInfo.getUseInstructionCount());
            mEtUseImportantCount.setText(reportsInfo.getUseImportantCount());
            mEtUseNewsCount.setText(reportsInfo.getUseNewsCount());

            mEtPhone.setText(reportsInfo.getPhone());
            mEtDutyLeader.setText(reportsInfo.getDutyLeader());
            mEtProblem.setText(reportsInfo.getProblem());
            mEtRemark.setText(reportsInfo.getRemark());

            mEtFireAlarmCount.setEnabled(false);
            mEtFireCarCount.setEnabled(false);
            mEtFireDeathCount.setEnabled(false);
            mEtFireEvacuationCount.setEnabled(false);
            mEtFireFireCount.setEnabled(false);
            mEtFireFiremanCount.setEnabled(false);
            mEtFireInjuredCount.setEnabled(false);
            mEtFireOutCount.setEnabled(false);
            mEtFireRescueCount.setEnabled(false);
            mEtFireUseCount.setEnabled(false);

            mEtRescueAlarmCount.setEnabled(false);
            mEtRescueCarCount.setEnabled(false);
            mEtRescueDeathCount.setEnabled(false);
            mEtRescueEvacuationCount.setEnabled(false);
            mEtRescueFiremanCount.setEnabled(false);
            mEtRescueInjuredCount.setEnabled(false);
            mEtRescueOutCount.setEnabled(false);
            mEtRescueRescueCount.setEnabled(false);
            mEtRescueUseCount.setEnabled(false);

            mEtExplosionAlarmCount.setEnabled(false);
            mEtExplosionCarCount.setEnabled(false);
            mEtExplosionDeathCount.setEnabled(false);
            mEtExplosionEvacuationCount.setEnabled(false);
            mEtExplosionFiremanCount.setEnabled(false);
            mEtExplosionInjuredCount.setEnabled(false);
            mEtExplosionRescueCount.setEnabled(false);
            mEtExplosionUseCount.setEnabled(false);

            mEtTrafficAlarmCount.setEnabled(false);
            mEtTrafficCarCount.setEnabled(false);
            mEtTrafficDeathCount.setEnabled(false);
            mEtTrafficFiremanCount.setEnabled(false);
            mEtTrafficInjuredCount.setEnabled(false);
            mEtTrafficRescueCount.setEnabled(false);
            mEtTrafficUseCount.setEnabled(false);

            mEtCollapseAlarmCount.setEnabled(false);
            mEtCollapseCarCount.setEnabled(false);
            mEtCollapseDeathCount.setEnabled(false);
            mEtCollapseEvacuationCount.setEnabled(false);
            mEtCollapseFiremanCount.setEnabled(false);
            mEtCollapseInjuredCount.setEnabled(false);
            mEtCollapseRescueCount.setEnabled(false);
            mEtCollapseUseCount.setEnabled(false);

            mEtReportInstructionCount.setEnabled(false);
            mEtReportImportantCount.setEnabled(false);
            mEtReportNewsCount.setEnabled(false);

            mEtUseInstructionCount.setEnabled(false);
            mEtUseImportantCount.setEnabled(false);
            mEtUseNewsCount.setEnabled(false);

            mEtPhone.setEnabled(false);
            mEtDutyLeader.setEnabled(false);
            mEtProblem.setEnabled(false);
            mEtRemark.setEnabled(false);

            mTvSave.setVisibility(View.GONE);
        }

        mTabs.setOnTabSelectedListener(new XTabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(XTabLayout.Tab tab) {
                resetView();
                if (tab.getPosition() == 0) {
                    mLlFire.setVisibility(View.VISIBLE);
                } else if (tab.getPosition() == 1) {
                    mLlRescue.setVisibility(View.VISIBLE);
                } else if (tab.getPosition() == 2) {
                    mLlExplosion.setVisibility(View.VISIBLE);
                } else if (tab.getPosition() == 3) {
                    mLlTraffic.setVisibility(View.VISIBLE);
                } else if (tab.getPosition() == 4) {
                    mLlCollapse.setVisibility(View.VISIBLE);
                }
            }

            @Override
            public void onTabUnselected(XTabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(XTabLayout.Tab tab) {

            }
        });
    }

    private void resetView() {
        mLlFire.setVisibility(View.GONE);
        mLlRescue.setVisibility(View.GONE);
        mLlExplosion.setVisibility(View.GONE);
        mLlTraffic.setVisibility(View.GONE);
        mLlCollapse.setVisibility(View.GONE);
    }

    @OnClick({R.id.iv_back, R.id.tv_save})
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_save:
                if (TextUtils.isEmpty(mEtPhone.getText().toString())) {
                    showShortToast("联系电话不可为空");
                    return;
                }
                if (TextUtils.isEmpty(mEtDutyLeader.getText().toString())) {
                    showShortToast("值班领导不可为空");
                    return;
                }
                if (actionInfo == null) {
                    actionInfo = new StatisticsInfoResult.DataBean();
                    setData();
                    saveReportInfo(actionInfo);
                } else {
                    setData();
                    updateReportInfo(actionInfo);
                }
                break;
        }
    }

    private void setData() {
        actionInfo.setFireAlarmCount(TextUtils.isEmpty(mEtFireAlarmCount.getText().toString()) ? "0" : mEtFireAlarmCount.getText().toString());
        actionInfo.setFireCarCount(TextUtils.isEmpty(mEtFireCarCount.getText().toString()) ? "0" : mEtFireCarCount.getText().toString());
        actionInfo.setFireDeathCount(TextUtils.isEmpty(mEtFireDeathCount.getText().toString()) ? "0" : mEtFireDeathCount.getText().toString());
        actionInfo.setFireEvacuationCount(TextUtils.isEmpty(mEtFireEvacuationCount.getText().toString()) ? "0" : mEtFireEvacuationCount.getText().toString());
        actionInfo.setFireFireCount(TextUtils.isEmpty(mEtFireFireCount.getText().toString()) ? "0" : mEtFireFireCount.getText().toString());
        actionInfo.setFireFiremanCount(TextUtils.isEmpty(mEtFireFiremanCount.getText().toString()) ? "0" : mEtFireFiremanCount.getText().toString());
        actionInfo.setFireInjuredCount(TextUtils.isEmpty(mEtFireInjuredCount.getText().toString()) ? "0" : mEtFireInjuredCount.getText().toString());
        actionInfo.setFireOutCount(TextUtils.isEmpty(mEtFireOutCount.getText().toString()) ? "0" : mEtFireOutCount.getText().toString());
        actionInfo.setFireRescueCount(TextUtils.isEmpty(mEtFireRescueCount.getText().toString()) ? "0" : mEtFireRescueCount.getText().toString());
        actionInfo.setFireUseCount(TextUtils.isEmpty(mEtFireUseCount.getText().toString()) ? "0" : mEtFireUseCount.getText().toString());

        actionInfo.setRescueAlarmCount(TextUtils.isEmpty(mEtRescueAlarmCount.getText().toString()) ? "0" : mEtRescueAlarmCount.getText().toString());
        actionInfo.setRescueCarCount(TextUtils.isEmpty(mEtRescueCarCount.getText().toString()) ? "0" : mEtRescueCarCount.getText().toString());
        actionInfo.setRescueDeathCount(TextUtils.isEmpty(mEtRescueDeathCount.getText().toString()) ? "0" : mEtRescueDeathCount.getText().toString());
        actionInfo.setRescueEvacuationCount(TextUtils.isEmpty(mEtRescueEvacuationCount.getText().toString()) ? "0" : mEtRescueEvacuationCount.getText().toString());
        actionInfo.setRescueFiremanCount(TextUtils.isEmpty(mEtRescueFiremanCount.getText().toString()) ? "0" : mEtRescueFiremanCount.getText().toString());
        actionInfo.setRescueInjuredCount(TextUtils.isEmpty(mEtRescueInjuredCount.getText().toString()) ? "0" : mEtRescueInjuredCount.getText().toString());
        actionInfo.setRescueOutCount(TextUtils.isEmpty(mEtRescueOutCount.getText().toString()) ? "0" : mEtRescueOutCount.getText().toString());
        actionInfo.setRescueRescueCount(TextUtils.isEmpty(mEtRescueRescueCount.getText().toString()) ? "0" : mEtRescueRescueCount.getText().toString());
        actionInfo.setRescueUseCount(TextUtils.isEmpty(mEtRescueUseCount.getText().toString()) ? "0" : mEtRescueUseCount.getText().toString());

        actionInfo.setExplosionAlarmCount(TextUtils.isEmpty(mEtExplosionAlarmCount.getText().toString()) ? "0" : mEtExplosionAlarmCount.getText().toString());
        actionInfo.setExplosionCarCount(TextUtils.isEmpty(mEtExplosionCarCount.getText().toString()) ? "0" : mEtExplosionCarCount.getText().toString());
        actionInfo.setExplosionDeathCount(TextUtils.isEmpty(mEtExplosionDeathCount.getText().toString()) ? "0" : mEtExplosionDeathCount.getText().toString());
        actionInfo.setExplosionEvacuationCount(TextUtils.isEmpty(mEtExplosionEvacuationCount.getText().toString()) ? "0" : mEtExplosionEvacuationCount.getText().toString());
        actionInfo.setExplosionFiremanCount(TextUtils.isEmpty(mEtExplosionFiremanCount.getText().toString()) ? "0" : mEtExplosionFiremanCount.getText().toString());
        actionInfo.setExplosionInjuredCount(TextUtils.isEmpty(mEtExplosionInjuredCount.getText().toString()) ? "0" : mEtExplosionInjuredCount.getText().toString());
        actionInfo.setExplosionRescueCount(TextUtils.isEmpty(mEtExplosionRescueCount.getText().toString()) ? "0" : mEtExplosionRescueCount.getText().toString());
        actionInfo.setExplosionUseCount(TextUtils.isEmpty(mEtExplosionUseCount.getText().toString()) ? "0" : mEtExplosionUseCount.getText().toString());

        actionInfo.setTrafficAlarmCount(TextUtils.isEmpty(mEtTrafficAlarmCount.getText().toString()) ? "0" : mEtTrafficAlarmCount.getText().toString());
        actionInfo.setTrafficCarCount(TextUtils.isEmpty(mEtTrafficCarCount.getText().toString()) ? "0" : mEtTrafficCarCount.getText().toString());
        actionInfo.setTrafficDeathCount(TextUtils.isEmpty(mEtTrafficDeathCount.getText().toString()) ? "0" : mEtTrafficDeathCount.getText().toString());
        actionInfo.setTrafficFiremanCount(TextUtils.isEmpty(mEtTrafficFiremanCount.getText().toString()) ? "0" : mEtTrafficFiremanCount.getText().toString());
        actionInfo.setTrafficInjuredCount(TextUtils.isEmpty(mEtTrafficInjuredCount.getText().toString()) ? "0" : mEtTrafficInjuredCount.getText().toString());
        actionInfo.setTrafficRescueCount(TextUtils.isEmpty(mEtTrafficRescueCount.getText().toString()) ? "0" : mEtTrafficRescueCount.getText().toString());
        actionInfo.setTrafficUseCount(TextUtils.isEmpty(mEtTrafficUseCount.getText().toString()) ? "0" : mEtTrafficUseCount.getText().toString());

        actionInfo.setCollapseAlarmCount(TextUtils.isEmpty(mEtCollapseAlarmCount.getText().toString()) ? "0" : mEtCollapseAlarmCount.getText().toString());
        actionInfo.setCollapseCarCount(TextUtils.isEmpty(mEtCollapseCarCount.getText().toString()) ? "0" : mEtCollapseCarCount.getText().toString());
        actionInfo.setCollapseDeathCount(TextUtils.isEmpty(mEtCollapseDeathCount.getText().toString()) ? "0" : mEtCollapseDeathCount.getText().toString());
        actionInfo.setCollapseEvacuationCount(TextUtils.isEmpty(mEtCollapseEvacuationCount.getText().toString()) ? "0" : mEtCollapseEvacuationCount.getText().toString());
        actionInfo.setCollapseFiremanCount(TextUtils.isEmpty(mEtCollapseFiremanCount.getText().toString()) ? "0" : mEtCollapseFiremanCount.getText().toString());
        actionInfo.setCollapseInjuredCount(TextUtils.isEmpty(mEtCollapseInjuredCount.getText().toString()) ? "0" : mEtCollapseInjuredCount.getText().toString());
        actionInfo.setCollapseRescueCount(TextUtils.isEmpty(mEtCollapseRescueCount.getText().toString()) ? "0" : mEtCollapseRescueCount.getText().toString());
        actionInfo.setCollapseUseCount(TextUtils.isEmpty(mEtCollapseUseCount.getText().toString()) ? "0" : mEtCollapseUseCount.getText().toString());

        actionInfo.setReportInstructionCount(TextUtils.isEmpty(mEtReportInstructionCount.getText().toString()) ? "0" : mEtReportInstructionCount.getText().toString());
        actionInfo.setReportImportantCount(TextUtils.isEmpty(mEtReportImportantCount.getText().toString()) ? "0" : mEtReportImportantCount.getText().toString());
        actionInfo.setReportNewsCount(TextUtils.isEmpty(mEtReportNewsCount.getText().toString()) ? "0" : mEtReportNewsCount.getText().toString());

        actionInfo.setUseInstructionCount(TextUtils.isEmpty(mEtUseInstructionCount.getText().toString()) ? "0" : mEtUseInstructionCount.getText().toString());
        actionInfo.setUseImportantCount(TextUtils.isEmpty(mEtUseImportantCount.getText().toString()) ? "0" : mEtUseImportantCount.getText().toString());
        actionInfo.setUseNewsCount(TextUtils.isEmpty(mEtUseNewsCount.getText().toString()) ? "0" : mEtUseNewsCount.getText().toString());

        actionInfo.setPhone(mEtPhone.getText().toString());
        actionInfo.setDutyLeader(mEtDutyLeader.getText().toString());
        actionInfo.setProblem(TextUtils.isEmpty(mEtProblem.getText().toString()) ? "" : mEtProblem.getText().toString());
        actionInfo.setRemark(TextUtils.isEmpty(mEtRemark.getText().toString()) ? "" : mEtRemark.getText().toString());
    }

    private void updateReportInfo(StatisticsInfoResult.DataBean actionInfo) {
        ModuleManager.getInstance().updateStatisticsReportInfoResult(actionInfo)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaseBean>() {
                    @Override
                    protected void hideDialog() {
                        stopProgressDialog();
                    }

                    @Override
                    protected void showDialog() {
                        startProgressDialog();
                    }

                    @Override
                    protected void onSuccess(BaseBean baseBean) {
                        showShortToast("保存成功");
                        finish();
                    }

                    @Override
                    protected void onFailure(String message) {
                        showShortToast(message);
                    }
                });
    }

    private void saveReportInfo(StatisticsInfoResult.DataBean actionInfo) {
        ModuleManager.getInstance().saveStatisticsReportInfoResult(actionInfo)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaseBean>() {
                    @Override
                    protected void hideDialog() {
                        stopProgressDialog();
                    }

                    @Override
                    protected void showDialog() {
                        startProgressDialog();
                    }

                    @Override
                    protected void onSuccess(BaseBean baseBean) {
                        showShortToast("保存成功");
                        finish();
                    }

                    @Override
                    protected void onFailure(String message) {
                        showShortToast(message);
                    }
                });
    }
}
